
// scllobj 滚动的class

// data-x  x轴偏移  默认是 0
// data-y  y轴偏移  默认是0 
// data-z  距离顶部 data-z的距离时移动距离结束 默认是 200px




$(document).ready(function() {
	
	$('.scllobj').each(function(){
				var _this=$(this);
				var csstxt="";
				var dx= _this.attr('data-x') ? _this.attr('data-x') : 0;
				var dy=_this.attr('data-y') ? _this.attr('data-y') : 0;
				var offsetTop=_this.attr('data-z') ? _this.attr('data-z') : 200;
				var ht=_this.offset().top-offsetTop;

					if(  ht >= $(window).scrollTop()  ){

						csstxt +="-webkit-transform:translate("+dx+'px,'+dy+"px);"
						csstxt +="-ms-transform:translate("+dx+'px,'+dy+"px);"
						csstxt +="-o-transform:translate("+dx+'px,'+dy+"px);"
						csstxt +="transform:translate("+dx+'px,'+dy+"px);"
					}else{
						csstxt +="-webkit-transform:translate(0,0);"
						csstxt +="-ms-transform:translate(0,0);"
						csstxt +="-o-transform:translate(0,0);"
						csstxt +="transform:translate(0,0);"
					}
					_this.attr('style','csstxt');

			});



	$(window).scroll(function(event) {

		$('.scllobj').each(function(){
				var _this=$(this);
				var offsetTop=_this.attr('data-z') ? _this.attr('data-z') : 200;
				var ht=_this.offset().top-offsetTop;
				var c=_this.attr('data-y') ? _this.attr('data-y') :0;
				var d=_this.attr('data-x') ? _this.attr('data-x') :0;
				var csstxt="";
				if( ht >= $(window).scrollTop() ){
					csstxt +="-webkit-transform:translate("+(-d*$(window).scrollTop()/ht + d*1)+'px,'+ (-c*$(window).scrollTop()/ht + c*1)+"px);"
					csstxt +="-ms-transform:translate("+(-d*$(window).scrollTop()/ht + d*1)+'px,'+ (-c*$(window).scrollTop()/ht + c*1)+"px);"
					csstxt +="-o-transform:translate("+( -d*$(window).scrollTop()/ht + d*1)+'px,'+  (-c*$(window).scrollTop()/ht + c*1)+"px);"
					csstxt +="transform:translate("+( -d*$(window).scrollTop()/ht + d*1)+'px,'+  (-c*$(window).scrollTop()/ht + c*1)+"px);"
					
					_this.attr('style',csstxt);
				}
			})

	})

});
